<?php


class DictionaryModel extends Model{
    //put your code here
    
    public function getPicDocCatagory(){
        
        $pid = $this->getPidByName('pdoc_catagory'); 
        $catagory = $this->where(array('pid'=>$pid))->order(array('order'=>'asc'))->select();
        return $catagory;
    }
    
    public function updatePicDocCatagory($catagoryInfoData){
        //$catagoryInfoData 是一个[{},{}]类型数据
        if(!empty($catagoryInfoData)){
            $pid = $this->getPidByName('pdoc_catagory');
            $res = $this->where(array('pid'=>$pid))->delete();
            if($res){
                for ($i = 0; $i < count($catagoryInfoData); $i++) {
                    $data['name'] = $catagoryInfoData[$i]['name'];
                    $data['order'] = $catagoryInfoData[$i]['order'];
                    $data['pid'] = $pid;
                    $this->add($data);
                }
            }
        }
    }
    
    private  function getPidByName($name){
        return $this->where(array('name'=>$name))->getField('id'); 
    }
    
    
}
